(********************************************************************)
(*	file: 		ADSPForwardReset.p									*)
(*	version:	.5alpha 											*)
(* 																	*)
(* Nondeterministically reset the output buffer and deallocate its	*)
(* data.															*)
(* In:	params[1] =	name of the entity to forward reset.			*)
(*																	*)
(* ----------------------------------------------------------------	*)
(* By:		Donald Koscheka											*)
(* Date:	1-Mar-88												*)
(* 			©	Copyright 1988, Apple Computer, Inc.				*)
(*			All Rights Reserved										*)
(*																	*)
(* ----------------------------------------------------------------	*)
(*						Modification History						*)
(* ----------------------------------------------------------------	*)
(*  Date	| By	|	 				Description					*)
(* ----------------------------------------------------------------	*)
(* 29-Mar-88| DK	| file created									*)
(* 17-Mar-88| DK	| ALPHA RELEASE									*)
(* ----------------------------------------------------------------	*)
(********************************************************************)

(*******************************************************************
							Build Sequence

pascal -o "{hpo}"ADSPForwardReset.p.o "{adsp}"ADSPForwardReset.p
link -m ENTRYPOINT  -rt XCMD=1307 -sn Main=ADSPForwardReset¶
	"{hpo}"ADSPForwardReset.p.o¶
	"{libraries}"Interface.o ¶
	"{plibraries}"paslib.o¶
	-o "{hp}"HyperADSPTest
		 
*******************************************************************)


{$R-}
{$S ADSPForwardReset}
UNIT DummyUnit;

(*******************************************************************)
INTERFACE 
(*******************************************************************)


Uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd, AppleTalk, ADSP, adspxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );



(*******************************************************************)
IMPLEMENTATION
(*******************************************************************)


PROCEDURE ADSPForwardReset( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
	Begin
		ADSPForwardReset( paramPtr );
	End;
	
	
Procedure ADSPForwardReset( paramPtr : XCmdPtr );
VAR
	adsp	: ADSPPtr;
	error	: OSErr;
	eAddr	: AddrBlock;
	cn		: cbPtr;
	tpb		: DSPParamBlock;
	
{$I XCmdGlue.inc }
{$I XCMDADSP.inc }	


BEGIN
	error := noErr;
	adsp := ADSPPtr(RetrieveHandle( GLOBALDSPDATA ));
	IF(adsp <> NIL) AND (paramPtr^.params[1] <> NIL) THEN
		BEGIN
			{*** (1) Get the entity's address 			***}
			adsp^.checkPoint := RECEIVING;
			HLock( paramPtr^.params[1] );

			eAddr := NBPGetAddress( paramPtr^.params[1]^ );
			cn := adsp^.ends;
			
			IF LongInt( eAddr ) <> 0 THEN {*** (2) Find entity in connection list***}
				WHILE cn <> NIL DO
					IF (LongInt(cn^.adr)=LongInt(eAddr)) AND (cn^.ccb.state=sOpen)THEN	
						IF( cn^.outBuf <> NIL ) THEN {*** are we sending ***}
							BEGIN
								WITH tpb DO
									BEGIN
										ioCompletion:= NIL;
										ioCRefNum 	:= adsp^.dspRefNum;
										csCode 		:= dspReset;
										ccbRefNum	:= cn^.ccbRef;
									END;
								error := PBControl( @tpb, SYNC );
								
								{*** deallocate the output buffer ***}
								IF cn^.outBuf <> NIL THEN
									BEGIN
										HUnlock( cn^.outBuf );
										DisposHandle( cn^.outBuf );
										cn^.outBuf := NIL;
									END;
								cn := NIL;
							END
						ELSE
							cn := cn^.next;
							
			HUnlock( Handle(paramPtr^.params[1]) );
			adsp^.checkPoint := CLOSE_OK;
		END;
	paramPtr^.returnValue := ErrorReturn( error );
END;


end.
